<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width,height=device-height,initial-scale=1,minimum-scale=1,user-scalable=no">		<meta http-equiv="X-UA-Compatible" content="ie=edge" />
    <link rel="stylesheet" type="text/css" href="/public/static/wx/css/base.css" />
    <link rel="stylesheet" type="text/css" href="/public/static/wx/font/font-awesome-4.7.0/css/font-awesome.css" />
    <link rel="stylesheet" type="text/css" href="/public/static/wx/plug-in/layui/css/layui.css" />
    <link rel="stylesheet" type="text/css" href="/public/static/wx/css/choose-engineer.css" />
    <script src="/public/static/wx/js/flex.js" type="text/javascript" charset="utf-8"></script>

    <title>可选电厂</title>
    <style>
        .active span{
            background-size: 22px !important;
            background-position: -1px -3px !important;
        }

        .head{
            background-size: 36px !important;
            background-position: 6px 10px !important;
        }
    </style>
</head>
<body>
<div class="index">
    <!--<div class="title">可选工程师</div>-->
    <div class="engineer-list" id="dataList">
        <!--<div class="engineer clearfix">
            <div class="head"></div>
            <div class="name">1号工程师</div>
            <span></span>
            <div class="level">中级</div>
        </div>-->

    </div>
</div>
<div class="certain" id="btn">确定</div>
<script src="/public/static/wx/js/jquery-3.3.1.min.js" type="text/javascript" charset="utf-8"></script>
<script src="/public/static/wx/plug-in/layui/layui.all.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript">
    var layer = layui.layer;
    var did = '{:input("id")}';
    var indexl = layer.load(0,{offset:['45%','45%']});

    $.post('{:url("powerQuery")}',{is_at:0},function (data) {
        $.post('{:url("powerList")}',{dis_id:did},function (resd) {
            layer.close(indexl);

            $.each(data.data,function (k,v) {

                var str = '<div class="engineer clearfix" aid="'+v.admin_id+'">\n' +
                    '            <div class="head"><img src="" alt=""></div>\n' +
                    '            <div class="name" style="font-size: 17px;">'+v.name+'('+v.username+')</div>\n' +
                    '            <span></span>\n' +
                    '            <div class="level">电厂</div>\n' +
                    '        </div>';

                if(!isid(resd['data'],v.admin_id)){
                    $('#dataList').append(str);
                }

            });


            $('.engineer').on('click',function(){
                $(this).toggleClass('active');
                $(this).toggleClass('ided');
            });
        });


    });


    function isid(data,id){
        for(let i=0;i<data.length;i++){
            if(data[i].admin_id==id){
                return true;
            }
        }
        return false;
    }


    $('#btn').click(function () {
        var ids = '';
        $('.ided').each(function (k,v) {
            ids += $(this).attr('aid')+',';
        });


        if(ids.length<=0){
            layer.msg('请选择',{icon:5});
            return;
        }
        var indexl = layer.load(0,{offset:['45%','45%']});
        $.post('{:url("powerAdd")}',{dis_id:did,aid:ids},function (res) {
            layer.close(indexl);
            if(res.code == 1){
                layer.msg(res.msg,{icon:6,shade:0.1},function () {
                    window.history.back();
                });
            }else{
                layer.msg(res.msg,{icon:5});
            }
        });

    });


</script>
</body>
</html>
